package tk.xboot.boot.conf;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * Client -> Listener -> ServletContainer -> Filter -> Servlet -> Interceptor
 */

@WebListener
public class ServletContextInitListener implements ServletContextListener {

    private static final String DEFAULT_HTML_ESCAPE = "defaultHtmlEscape";

    /**
     * Receives notification that the web application initialization
     * process is starting.
     *
     * <p>All ServletContextListeners are notified of context
     * initialization before any filters or servlets in the web
     * application are initialized.
     *
     * @param sce the ServletContextEvent containing the ServletContext
     *            that is being initialized
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        String param = sce.getServletContext().getInitParameter(DEFAULT_HTML_ESCAPE);
        if(null == param)
            sce.getServletContext().setInitParameter(DEFAULT_HTML_ESCAPE,"true");
    }

    /**
     * Receives notification that the ServletContext is about to be
     * shut down.
     *
     * <p>All servlets and filters will have been destroyed before any
     * ServletContextListeners are notified of context
     * destruction.
     *
     * @param sce the ServletContextEvent containing the ServletContext
     *            that is being destroyed
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // Nothing to do.
    }
}
